package com.xiaoxiao.cateye.library.util;

import com.xiaoxiao.cateye.library.R;

import java.util.ArrayList;

import me.rosuh.filepicker.bean.FileItemBeanImpl;
import me.rosuh.filepicker.config.AbstractFileFilter;
import me.rosuh.filepicker.filetype.FileType;

public class SqliteFileFilter extends AbstractFileFilter {
    public static final int REQUEST_CODE = 0x102;
    @Override
    public ArrayList<FileItemBeanImpl> doFilter(ArrayList<FileItemBeanImpl> arrayList) {
        ArrayList<FileItemBeanImpl> fileItemBeans = new ArrayList<>();
        for (FileItemBeanImpl fileItemBean : arrayList){
            if (fileItemBean.isChecked() || fileItemBean.isDir() ||
                    fileItemBean.getFileName().endsWith(".sqlite")||fileItemBean.getFileName().endsWith(".db")){
                if (fileItemBean.getFileName().endsWith(".sqlite")||fileItemBean.getFileName().endsWith(".db")){
                    fileItemBean.setFileType(new SqliteFileType());
                }
                fileItemBeans.add(fileItemBean);
            }
        }
        return fileItemBeans;
    }

    class SqliteFileType implements FileType {

        @Override
        public int getFileIconResId() {
            return R.drawable.icon_map;
        }

        @Override
        public String getFileType() {
            return "sqlite";
        }

        @Override
        public boolean verify(String fileName) {
            return fileName!=null&&(fileName.toLowerCase().endsWith(".sqlite")||fileName.toLowerCase().endsWith(".db"));
        }
    }
}
